Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Breaking Change] Update UDF validator to treat null/empty values as valid #80

Merged

Conversation

homestar9
Copy link
Contributor

@homestar9 homestar9 commented Sep 9, 2023

Updated for consistency (see ortus-docs/cbvalidation-docs#13) and will treat null/empty values as valid. Developers who want to dynamically determine whether a field should be required will need to switch to using theRequiredIf validator.

Warning: This PR should be viewed as a breaking change and reserved for the next major version of CBValidation.

homestar9 added a commit to homestar9/cbvalidation-docs that referenced this pull request Sep 9, 2023
Update description for UDF validator once coldbox-modules/cbvalidation#80 goes live.
if ( isNull( arguments.targetValue ) || isNullOrEmpty( arguments.targetValue ) ) {
return true;
}

// Validate via method
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The only issue I see here, is that if arguments.targetValue is null, then line 46 will fail

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure I follow. If arguments.targetValue is null, the method will return true, so it should never get to line 46.

// Validate against the UDF/closure
var passed = arguments.validationData(
isNull( arguments.targetValue ) ? javacast( "null", "" ) : arguments.targetValue,
arguments.targetValue,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am thinking that if the value is actually null, this will fail, did you try it?

Copy link
Contributor Author

@homestar9 homestar9 Sep 13, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@lmajano I haven't tested it in production, but I updated the UDFValidatorTest.cfc lines 30-37 to account for passing a null value and the validator returns true. Do you want me to create a temporary repo to test the validator instead of relying on Testbox?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Forget it, the way it was reading on my phone it was that lines 37-41 where removed.

@lmajano lmajano merged commit a8cbe0b into coldbox-modules:development Sep 14, 2023
@lmajano
Copy link
Contributor

lmajano commented Sep 14, 2023

Ok, can you make sure this works @homestar9 it's now in be once it builds. https://github.com/coldbox-modules/cbvalidation/actions/runs/6183950316

@homestar9
Copy link
Contributor Author

@lmajano tested be and working!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants